
package com.fantasy;

import com.fantasy.R;
import com.fantasy.ui.ConversionActivity;
import com.fantasy.ui.MainWimActivity;
import com.fantasy.ui.WimSocketClientActivitiy;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

public class WimNotificationManager {
	NotificationManager mNM;
	private Context mContext;

	public WimNotificationManager(Context context) {
		mContext = context;
		mNM = (NotificationManager) mContext
				.getSystemService(mContext.NOTIFICATION_SERVICE);
	}

	public void showRunningNotification() {
		CharSequence text = mContext.getText(R.string.application_running);
		Notification notification = new Notification(R.drawable.stat_sample,
				text, System.currentTimeMillis());
		notification.flags |= Notification.FLAG_ONGOING_EVENT;
		Intent contentIntent = new Intent();
		contentIntent.putExtra("WIM", true);
		contentIntent.setClass(mContext, MainWimActivity.class);
		PendingIntent pendIntent = PendingIntent.getActivity(mContext, 0,
				contentIntent, 0);
		notification.setLatestEventInfo(mContext, text, text, pendIntent);
		mNM.notify(R.string.application_running, notification);
	}

	public void showNotification(String incomingMsg) {
		// In this sample, we'll use the same text for the ticker and the
		// expanded notification
		CharSequence text = mContext.getText(R.string.app_name);

		// Set the icon, scrolling text and timestamp
		Notification notification = new Notification(R.drawable.stat_sample,
				incomingMsg, System.currentTimeMillis());

		// The PendingIntent to launch our activity if the user selects this
		// notification
		PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0,
				new Intent(mContext, MainWimActivity.class), 0);

		// Set the info for the views that show in the notification panel.
		notification.setLatestEventInfo(mContext, mContext
				.getText(R.string.incoming_new_message), incomingMsg,
				contentIntent);

		// Send the notification.
		// We use a string id because it is a unique number. We use it later to
		// cancel.
		mNM.notify(R.string.incoming_new_message, notification);
	}

	public void handleError(int resId) {
		CharSequence text = mContext.getText(resId);

		// Set the icon, scrolling text and timestamp
		Notification notification = new Notification(R.drawable.stat_sample,
				text, System.currentTimeMillis());

		// The PendingIntent to launch our activity if the user selects this
		// notification
		PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0,
				new Intent(mContext, WimSocketClientActivitiy.class), 0);

		// Set the info for the views that show in the notification panel.
		notification.setLatestEventInfo(mContext, mContext
				.getText(R.string.socket_error), text, contentIntent);

		// Send the notification.
		// We use a string id because it is a unique number. We use it later to
		// cancel.
		mNM.notify(R.string.incoming_new_message, notification);
	}

	public void cancelNotifcation() {
		mNM.cancelAll();
	}

	public void cancelComingMsgNotification() {
		mNM.cancel(R.string.incoming_new_message);
	}

	public void cancelRunningNotification() {
		mNM.cancel(R.string.application_running);
	}
}
